//
//  RequestNetWork.m
//  MyNetworkingRequest
//
//  Created by myApple on 15/3/19.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "PromptInfoView.h"

@interface PromptInfoView ()
{
    UILabel * infoLabel;
}

@end

//static float timer;
static NSDate * lastDate;
static NSDate * nowDate;


@implementation PromptInfoView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
    }
    return self;
}



+(void)showMessage:(NSString *)message
{
  
    nowDate = [NSDate date];
    NSTimeInterval result = [nowDate timeIntervalSinceDate:lastDate];
    
    if (result<3.0) {
//        NSLog(@"result = %f",result);
        return;
    }
    
    float screenWidth = [UIScreen mainScreen].bounds.size.width;
    float screenHeight = [UIScreen mainScreen].bounds.size.height;
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    UIView *showview =  [[UIView alloc]init];
    showview.backgroundColor = [UIColor blackColor];
    showview.frame = CGRectMake(1, 1, 1, 1);
    showview.alpha = 1.0f;
    showview.layer.cornerRadius = 5.0f;
    showview.layer.masksToBounds = YES;
    [window addSubview:showview];
    
    UILabel *label = [[UILabel alloc]init];
    CGRect LabelSize = [message boundingRectWithSize:CGSizeMake(screenWidth - 20, 9000 ) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName] context:nil];
    label.frame = CGRectMake(10, 5, LabelSize.size.width, LabelSize.size.height);
    label.text = message;
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 2;
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:15];
    [showview addSubview:label];
    showview.frame = CGRectMake((screenWidth- LabelSize.size.width - 20)/2, screenHeight - 200, LabelSize.size.width+20, LabelSize.size.height+10);
    [UIView animateWithDuration:3.0 animations:^{

        showview.alpha = 0;
        
        CGRect rect = [showview frame];
        //        rect.origin.x = 100;
        rect.origin.y = [UIScreen mainScreen].bounds.size.height - 150;
        [showview setFrame:rect];
        
        //放大
//        showview.transform = CGAffineTransformMakeScale(1.2, 1.2);
        
        lastDate  = [NSDate date];
        
    } completion:^(BOOL finished) {
        [showview removeFromSuperview];

    }];
    

}






+(void)showMessage:(NSString *)message superView:(UIView *)view
{
    nowDate = [NSDate date];
    NSTimeInterval result = [nowDate timeIntervalSinceDate:lastDate];
    
    if (result<3.0) {
        //        NSLog(@"result = %f",result);
        return;
    }
    
    float screenWidth = [UIScreen mainScreen].bounds.size.width;
    float screenHeight = [UIScreen mainScreen].bounds.size.height;
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    UIView *showview =  [[UIView alloc]init];
    showview.backgroundColor = [UIColor blackColor];
    showview.frame = CGRectMake(1, 1, 1, 1);
    showview.alpha = 1.0f;
    showview.layer.cornerRadius = 5.0f;
    showview.layer.masksToBounds = YES;
    if (view == nil) {
        [window addSubview:showview];
    }
    else
    {
    [view addSubview:showview];
    }
    
    UILabel *label = [[UILabel alloc]init];
    CGRect LabelSize = [message boundingRectWithSize:CGSizeMake(screenWidth - 20, 9000 ) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName] context:nil];
    label.frame = CGRectMake(10, 5, LabelSize.size.width, LabelSize.size.height);
    label.text = message;
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 2;
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:15];
    [showview addSubview:label];
    showview.frame = CGRectMake((screenWidth- LabelSize.size.width - 20)/2, screenHeight - 300, LabelSize.size.width+20, LabelSize.size.height+10);
    [UIView animateWithDuration:3.0 animations:^{
        showview.alpha = 0;
        CGRect rect = [showview frame];
        //        rect.origin.x = 100;
        rect.origin.y = [UIScreen mainScreen].bounds.size.height - 200;
        [showview setFrame:rect];
        
        lastDate  = [NSDate date];
        
    } completion:^(BOOL finished) {
        [showview removeFromSuperview];
    }];

}


@end
